import { addComments, deleteComments, getComments, updateComments, uploadComments } from '@/api/forums/comment';
import CommonTable from '@/components/Table';
import React, { useRef, useState } from 'react';
import SearchBar from './Search';
import { Button, Drawer, Tag } from 'antd';
import { TagsItem } from '@/api/tags';
import { ColumnType } from 'antd/es/table';
import AddForm from './AddForm';
import EditForm from './EditForm';
import MarkDownComponent from '@/components/markdown';
import { CommentsItem } from '@/api/forums/comment';

const defaultColumn: ColumnType<CommentsItem>[] = [
  {
    title: '用户ID',
    key: 'userID',
    dataIndex: 'userID'
  },
  {
    title: '内容',
    key: 'content',
    dataIndex: 'content'
  },
  {
    title: '帖子ID',
    key: 'forumID',
    dataIndex: 'forumID'
  }
];

export default function PostsManagement() {
  const [tagsData, setTagsData] = useState<CommentsItem[]>([]);
  const [recorde, setRecord] = useState<CommentsItem>();
  const formRef = useRef();
  const handleChange = (data: CommentsItem[]) => setTagsData(data);
  const handleRecordChange = (data: CommentsItem, form: any) => {
    setRecord(data);
    formRef.current = form;
  };

  return (
    <>
      <CommonTable
        title="帖子"
        deleteApi={deleteComments}
        getDataApi={getComments}
        updateDataApi={updateComments}
        addDataApi={addComments}
        columns={defaultColumn}
        onChange={handleChange}
        onRecordChange={handleRecordChange}
        // EditForm={<EditForm data={recorde} form={formRef.current} />}
        SerchBar={<SearchBar />}
      />
    </>
  );
}
